package com.uenpay.oem.ui.settings;

import android.app.NotificationManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.qyx.android.database.TalkMsgManager;
import com.qyx.android.database.TopListMsgManager;
import com.uenpay.im.BroadcastAction;
import com.uenpay.im.IMApplication;
import com.uenpay.im.callback.IOnBottomDialogListener;
import com.uenpay.im.ui.old.activity.PushServiceConn;
import com.uenpay.im.ui.old.activity.chat.ActivityHandle;
import com.uenpay.im.ui.old.activity.personal.SettingActivity;
import com.uenpay.im.ui.old.activity.personal.UpdatePwdActivity;
import com.uenpay.im.ui.old.activity.pwd.SetPayPwdActivity;
import com.uenpay.im.utilities.ToastUtil;
import com.uenpay.im.weight.BottomDialog2;
import com.uenpay.im.weight.DialogUtility;
import com.uenpay.oem.MyApplication;
import com.uenpay.oem.R;
import com.uenpay.oem.ui.user.login.LoginActivity;
import com.uenpay.util.app.ActivityStack;
import com.uenpay.util.app.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by PS on 2017/6/20.
 */

public class SettingsActivity extends BaseActivity {
	@BindView(R.id.iv_gesture_login)
	ImageView ivGestureLogin;
	@BindView(R.id.iv_passworid_login)
	ImageView ivPassworidLogin;
	@BindView(R.id.iv_music)
	ImageView ivMusic;
	private TopListMsgManager topListMsgManager = new TopListMsgManager();
	private TalkMsgManager takeMsgManager = new TalkMsgManager();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View bindView() {
		return null;
	}

	@Override
	public int bindLayout() {
		return R.layout.activity_seeting;
	}

	@Override
	public void initView(View view) {
		setTitle("设置");
	}
	boolean isgesture=false;
	boolean ispassworid=false;
	boolean ismusic=false;
	@OnClick({ R.id.rl_login_psd, R.id.rl_play_psd, R.id.rl_densefree, R.id.iv_gesture_login, R.id.iv_passworid_login, R.id.iv_music,
			R.id.rl_facility, R.id.rl_clean, R.id.btn_seetings })
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.rl_login_psd:
			ActivityHandle.startActivity(SettingsActivity.this,
					UpdatePwdActivity.class, null, -1);
			break;
		case R.id.rl_play_psd:
			Intent intent = new Intent(SettingsActivity.this,
					SetPayPwdActivity.class);
			startActivity(intent);
			break;
		case R.id.rl_densefree:
			ToastUtil.showToast(getApplicationContext(), "暂未开放");

			break;
		case R.id.iv_gesture_login:
			/*if (isgesture){
				isgesture=true;
				ivGestureLogin.setImageResource(R.drawable.iv_closebutton);
			}else {
				ivGestureLogin.setImageResource(R.drawable.iv_openbutton);
			}
			isgesture=!isgesture;*/

			ToastUtil.showToast(getApplicationContext(), "暂未开放");
			break;
		case R.id.iv_passworid_login:
		/*	if (ispassworid){
				ispassworid=true;
				ivPassworidLogin.setImageResource(R.drawable.iv_closebutton);
			}else {
				ivPassworidLogin.setImageResource(R.drawable.iv_openbutton);
			}
			ispassworid=!ispassworid;*/

			ToastUtil.showToast(getApplicationContext(), "暂未开放");

			break;
		case R.id.iv_music:
		/*	if (ismusic){
				ismusic=true;
				ivMusic.setImageResource(R.drawable.iv_closebutton);
			}else {
				ivMusic.setImageResource(R.drawable.iv_openbutton);
			}
			ismusic=!ismusic;*/
			ToastUtil.showToast(getApplicationContext(), "暂未开放");
			break;
		case R.id.rl_facility:
			ToastUtil.showToast(getApplicationContext(), "暂未开放");
			break;
		case R.id.rl_clean:
			clearHistory();
			break;
		case R.id.btn_seetings:

			showExitDialog();
			break;
		}
	}

	/**
	 * 清除所有消息
	 */
	private void clearHistory() {

		DialogUtility.showDialog(SettingsActivity.this, com.uenpay.im.R.string.clear_all_msg,
				com.uenpay.im.R.string.clear, com.uenpay.im.R.string.cancel, true,
				new IOnBottomDialogListener() {

					@Override
					public void onClicked() {
						// 清除会话消息
						takeMsgManager.clearEmpty();
						// 清除会话列表消息
						topListMsgManager.clearEmpty();
						// 通知会话列表刷新数据
						Intent intent = new Intent();
						intent.setAction(BroadcastAction.ACTION_CLEAR_MSG_COUNT);
						sendBroadcast(intent);
						IMApplication.showToast(getResources().getString(
								com.uenpay.im.R.string.delete_completed));
						finish();
					}
				});

	}

	private void showExitDialog() {
		BottomDialog2.showBottomDialog(this,
				getResources().getString(com.uenpay.im.R.string.exit_app_dialog), "", "", -1,
				new IOnBottomDialogListener() {

					@Override
					public void onClicked() {
						exitApp();
					}
				});
	}

	// 退出APP
	private void exitApp() {
		PushServiceConn.getInstance(this).stopChatService();
		MyApplication.notification_sum = 0;
		NotificationManager mNotificationManager = (NotificationManager) MyApplication
				.getAppContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
		mNotificationManager.cancel(0);
		MyApplication.IS_GET_ALL_FRIENDS = true;
//        IMApplication.getInstance().ClearAllActivity();
		ActivityStack.getInstance().popAll();
		startActivity(new Intent(this, LoginActivity.class));

	}
}
